using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using DOMercury.Interfaces;
using DOMercury.Items;


namespace FolderContentsPlugin
{
    //Template Sub Index, which is a subset of IItems depending on the parent item
    [DOMercuryPlugIn("Description of Plugin - Not really used anywhere")]
    public class TemplateSubIndex : ISubIndex
    {
        #region ISubIndex Members

        //If true, sub index searching will be treated like standard index searching, if false, entire sub index will be displayed in Suggestions box
        public bool EnableSearch
        {
            get { return true; }
        }

        //Returns the subIndex to DOMercury, takes in the parent item and current action to allow specific sub indexes to be returned.
        public List<IItem> GetSubIndex(IItem item, IAction action)
        {
            List<IItem> si = new List<IItem>();
            try
            {

                foreach (string folder in Directory.GetDirectories(item.DisplayDesc))
                {
                    List<PathItem> l = new List<PathItem>();
                    l.Add(new PathItem(folder, Path.GetFileName(folder)));
                    si.Add(new ItemsList(l));
                }
            }
            catch { }
            try
            {
                foreach (string path in Directory.GetFiles(item.DisplayDesc))
                {
                    List<PathItem> l = new List<PathItem>();
                    l.Add(new PathItem(path, Path.GetFileName(path)));
                    si.Add(new ItemsList(l));
                }
            }
            catch { }
            return si;
        }

        //The ItemType of the parent for which this sub index will be provided
        public string ParentItemType
        {
            get { return "folder"; }
        }


        //Description of your parameters provider
        public string Description
        {
            get { return "Creates a sub index containing the file and folder items in the folder"; }
        }

        //Name of your parameters provider
        public string Name
        {
            get { return "FolderContents Plugin"; }
        }

        //Tells the Plugin Details form whether to enable the Show Options Button
        public bool HasOptions
        {
            get { return false; }
        }

        //If you have an options form, call the ShowDialog method on it here.
        public void ShowOptions()
        {
           //DO Nothing
        }

        #endregion
    }

}
